//
//  ZCOrderDetailVC.m
//  ZCJZ
//
//  Created by sujeking on 2019/3/7.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import "ZCOrderDetailVC.h"
#import "ZCOrderPayHeadView.h"
#import "ZCOrderViewModel.h"
#import "ZCOrderDetailAddressCell.h"
#import "ZCOrderCheckLeftAndRightCell.h"
#import "ZCOrderCheckSectionHeadView.h"
#import "ZCOrderCheckGoodsInfoCell.h"
#import "ZCOrderDetailLogisticsCell.h"

#import "ZCLogisticsVC.h"

#import "ZCOrderCanselResionVC.h"
#import "TBCityIconFont.h"
#import "ZCOrderConst.h"
#import "ZCOrderPayVC.h"
#import <BlocksKit+UIKit.h>

@interface ZCOrderDetailVC ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *toolBar;
@property (weak, nonatomic) IBOutlet UIStackView *sview;

@property (nonatomic, copy) NSDictionary *datasource;

@property (nonatomic, copy) NSArray *staticArr;

@end

@implementation ZCOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self netFetchOrderDetail];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

}

- (void)setupUI {
    self.navTitle = @"订单详情";
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCOrderDetailAddressCell" bundle:nil] forCellReuseIdentifier:@"ZCOrderDetailAddressCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCOrderCheckLeftAndRightCell" bundle:nil]
         forCellReuseIdentifier:@"ZCOrderCheckLeftAndRightCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCOrderCheckGoodsInfoCell" bundle:nil]
         forCellReuseIdentifier:@"ZCOrderCheckGoodsInfoCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCOrderDetailLogisticsCell" bundle:nil] forCellReuseIdentifier:@"ZCOrderDetailLogisticsCell"];
    
    
    UIImage *img = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e623", 20, [generalToolBox getColorWithHexadecimalColorStr:@"0xffffff"])];
    [self setRightItemWithIcon:img action:@selector(loadChatVC)];
    
    
    UIView *footerView = [[UIView alloc] initWithFrame:(CGRect){0,0,ScreenWidth,72}];
    self.tableView.tableFooterView = footerView;
    
    
    self.toolBar.layer.shadowColor = [UIColor grayColor].CGColor;
    self.toolBar.layer.shadowOffset = CGSizeMake(0, -1);
    self.toolBar.layer.shadowOpacity = 0.5;
    
    self.toolBar.hidden = YES;
    for (UIButton *btn in self.sview.subviews) {
        if (btn.tag >= 20) {
            btn.layer.borderWidth = 0.5f;
          btn.layer.borderColor = [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"].CGColor;
            btn.layer.cornerRadius = 2.0f;
            btn.layer.masksToBounds = YES;
        }
    }
}

- (void)updateBarView {
    __weak typeof(self) weakSelf = self;
    NSInteger status = [[self.datasource valueForKey:@"status"] integerValue];
    self.toolBar.hidden = NO;
    switch (status) {
        case STATUS_AFTER_SALES:
        {
            self.toolBar.hidden = YES;
        }
            break;
        case STATUS_CANCEL:
        {
            self.toolBar.hidden = YES;
        }
            break;
        case STATUS_CLOSE:
        {
            UIButton *btn20 = [self.sview viewWithTag:20];
        
            [self hiddenButtonWithTag:21];
            [self hiddenButtonWithTag:22];
            [self hiddenButtonWithTag:23];
            [self hiddenButtonWithTag:24];
            
            [btn20 setTitle:@"再次购买" forState:UIControlStateNormal];
            [self setButtonHeightLight:btn20];
            
            [btn20 bk_addEventHandler:^(id sender) {
//                WZGGoodsDetailVC *vc = [[WZGGoodsDetailVC alloc] init];
//                NSArray *orderExtend = [self.datasource valueForKey:@"orderExtend"];
//                NSDictionary *dict = orderExtend.firstObject;
//                vc.idstr = [dict valueForKey:@"goods_id"];
//                vc.bargainId = 0;
//                [self.navigationController pushViewController:vc animated:YES];
            } forControlEvents:UIControlEventTouchUpInside];
        }
            break;
        case STATUS_WAIT_SEND:
        {
            UIButton *btn20 = [self.sview viewWithTag:20];
            [self hiddenButtonWithTag:21];
            [self hiddenButtonWithTag:22];
            [self hiddenButtonWithTag:23];
            [self hiddenButtonWithTag:24];
            
            NSInteger type = [[self.datasource valueForKey:@"type"] intValue];
            if (type == 16) {
                [self hiddenButtonWithTag:20];
                return;
            }
            
            [btn20 setTitle:@"取消订单" forState:UIControlStateNormal];
            [btn20 bk_addEventHandler:^(id sender) {
                NSInteger type = [[self.datasource valueForKey:@"type"] integerValue];
                if (type == 3) { //拼团不可以取消
                    [self.view makeToast:@"拼团订单不可取消" duration:2.0 position:CSToastPositionCenter];
                    return;
                }
                [self netFetchOrderCanselResion];
            } forControlEvents:UIControlEventTouchUpInside];
        }
            break;
        case STATUS_WAIT_GET:
        {
            UIButton *btn20 = [self.sview viewWithTag:20];
            UIButton *btn21 = [self.sview viewWithTag:21];
            UIButton *btn22 = [self.view viewWithTag:22];
            
            [self hiddenButtonWithTag:23];
            [self hiddenButtonWithTag:24];
            
            [btn20 setTitle:@"申请售后" forState:UIControlStateNormal];
            [btn21 setTitle:@"确认收货" forState:UIControlStateNormal];
            [btn22 setTitle:@"查看物流" forState:UIControlStateNormal];
            
            [btn20 bk_addEventHandler:^(id sender) {
//                ZCAfterSaleChoiceApplyClassVC *vc = [[ZCAfterSaleChoiceApplyClassVC alloc] init];
//                vc.dataDic = @{@"id":weakSelf.ids,@"goods_id":[weakSelf.datasource valueForKey:@"goods_id"]};
//                [weakSelf.navigationController pushViewController:vc animated:YES];
            } forControlEvents:UIControlEventTouchUpInside];

            
            [btn21 bk_addEventHandler:^(id sender) {
                __weak typeof(self) weakSelf = self;
                [self showAlert:@"提示" content:@"是否确认收货" actionStr1:@"确认" style:UIAlertActionStyleDefault actionAc1:^(UIAlertAction * _Nonnull action) {
                    [weakSelf netConfirmReceipt];
                } actionStr2:@"取消" style:UIAlertActionStyleCancel actionAc:^(UIAlertAction * _Nonnull action) {
                    
                }];
            } forControlEvents:UIControlEventTouchUpInside];
            
            [btn22 bk_addEventHandler:^(id sender) {
                ZCLogisticsVC *vc = [[ZCLogisticsVC alloc] init];
                vc.logisticId = [self.datasource valueForKey:@"logistics_sn"];
                vc.expressId = [self.datasource valueForKey:@"express_code"];
                [self.navigationController pushViewController:vc animated:YES];
            } forControlEvents:UIControlEventTouchUpInside];
        }
            break;
        case STATUS_WAIT_PAY:
        {
            UIButton *btn20 = [self.sview viewWithTag:20];
            UIButton *btn21 = [self.sview viewWithTag:21];
            [self hiddenButtonWithTag:22];
            [self hiddenButtonWithTag:23];
            [self hiddenButtonWithTag:24];
            
            [btn20 setTitle:@"立即支付" forState:UIControlStateNormal];
            [btn21 setTitle:@"取消订单" forState:UIControlStateNormal];
            [self setButtonHeightLight:btn20];
            
            NSInteger type = [[self.datasource valueForKey:@"type"] intValue];
            if (type == 16) {
                [self hiddenButtonWithTag:21];
            }

            [btn20 bk_addEventHandler:^(id sender) {
                NSInteger goods_sale_type = [[self.datasource valueForKey:@"goods_sale_type"] integerValue];
                if (goods_sale_type == 1) {
                    [self.view makeToast:@"啊哦,该商品已下架,不能支付了" duration:2.0 position:CSToastPositionCenter];
                } else {
                    ZCOrderPayVC *vc = [[ZCOrderPayVC alloc] init];
                    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.datasource];
                    [dict setValue:[self.datasource valueForKey:@"id"] forKey:@"order_id"];
                    vc.dict = dict;
                    vc.isOrderList = NO;
                    [self.navigationController pushViewController:vc animated:YES];
                }
            } forControlEvents:UIControlEventTouchUpInside];
            
            [btn21 bk_addEventHandler:^(id sender) {
                NSInteger type = [[self.datasource valueForKey:@"type"] integerValue];
                if (type == 3) { //拼团不可以取消
                    [self.view makeToast:@"拼团订单不可取消" duration:2.0 position:CSToastPositionCenter];
                    return;
                }
                [self netFetchOrderCanselResion];
            } forControlEvents:UIControlEventTouchUpInside];
            
        }
            break;
        case STATUS_WAIT_FEEDBACK:
        case STATUS_END:
        {
            UIButton *btn20 = [self.sview viewWithTag:20];
            UIButton *btn21 = [self.sview viewWithTag:21];
//            UIButton *btn22 = [self.sview viewWithTag:22];
            UIButton *btn23 = [self.sview viewWithTag:23];
            
            [self hiddenButtonWithTag:22];
            [self hiddenButtonWithTag:24];
            [self hiddenButtonWithTag:23];
            [btn20 setTitle:@"申请售后" forState:UIControlStateNormal];
            [btn21 setTitle:@"再次购买" forState:UIControlStateNormal];
//            [btn22 setTitle:@"评价商品" forState:UIControlStateNormal];
            [btn23 setTitle:@"删除订单" forState:UIControlStateNormal];
            
            [btn20 bk_addEventHandler:^(id sender) {
//                ZCAfterSaleChoiceApplyClassVC *vc = [[ZCAfterSaleChoiceApplyClassVC alloc] init];
//                vc.dataDic = @{@"id":weakSelf.ids,@"goods_id":[weakSelf.datasource valueForKey:@"goods_id"]};
//                [weakSelf.navigationController pushViewController:vc animated:YES];
                
            } forControlEvents:UIControlEventTouchUpInside];
            
            [btn21 bk_addEventHandler:^(id sender) {
//                WZGGoodsDetailVC *vc = [[WZGGoodsDetailVC alloc] init];
//                NSArray *orderExtend = [self.datasource valueForKey:@"orderExtend"];
//                NSDictionary *dict = orderExtend.firstObject;
//                vc.idstr = [dict valueForKey:@"goods_id"];
//                vc.bargainId = 0;
//                [self.navigationController pushViewController:vc animated:YES];
            } forControlEvents:UIControlEventTouchUpInside];
            
            
//            [btn22 bk_addEventHandler:^(id sender) {
//                ZCCommentVC *vc = [[ZCCommentVC alloc] init];
//                [self.navigationController pushViewController:vc animated:YES];
//
//            } forControlEvents:UIControlEventTouchUpInside];
            
            [btn23 bk_addEventHandler:^(id sender) {
                __weak typeof(self) weakSelf = self;
                [self showAlert:@"提示" content:@"是否确定删除订单" actionStr1:@"取消" style:UIAlertActionStyleDefault actionAc1:^(UIAlertAction * _Nonnull action) {
                } actionStr2:@"删除" style:UIAlertActionStyleDestructive actionAc:^(UIAlertAction * _Nonnull action) {
                    [weakSelf netDelOrder];
                }];
            } forControlEvents:UIControlEventTouchUpInside];
            
        }
            break;
        default:
            break;
    }
}

- (void)setButtonHeightLight:(UIButton *)btn {
    [btn setBackgroundColor:[generalToolBox getColorWithHexadecimalColorStr:@"0xC20114"]];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}

- (void)hiddenButtonWithTag:(NSInteger)tag {
    UIButton *btn = [self.sview viewWithTag:tag];
//    btn.hidden = YES;
    btn.alpha = 0;
}

// MARK: - UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        NSInteger status = [[self.datasource valueForKey:@"status"] integerValue];
        if (status == STATUS_CANCEL
            || status == STATUS_WAIT_PAY
            || status == STATUS_WAIT_SEND
            || status == STATUS_CLOSE) {
            return 1;
        } else {
            return 2;
        }
    }
    if (section == 1) {
        NSArray *orderExtend = [self.datasource valueForKey:@"orderExtend"];
        return orderExtend.count;
    }
    if (section == 2) {
        NSArray *arr = self.staticArr.firstObject;
        NSString *send_time = [self.datasource valueForKey:@"send_time"];
        NSString *pay_time = [self.datasource valueForKey:@"pay_time"];
        if (pay_time == nil || pay_time.length == 0) {
            return arr.count - 2;
        } else if (send_time == nil || send_time.length == 0) {
            return arr.count - 1;
        } else {
            return arr.count;
        }
    }
    if (section == 3) {
        NSArray *arr = self.staticArr.lastObject;
        return arr.count;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = indexPath.row;
    NSInteger section = indexPath.section;
    switch (section) {
        case 0:
        {
            NSInteger status = [[self.datasource valueForKey:@"status"] integerValue];
            if (status == STATUS_CANCEL
                || status == STATUS_WAIT_PAY
                || status == STATUS_WAIT_SEND) {
                ZCOrderDetailAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderDetailAddressCell"
                                                                                 forIndexPath:indexPath];
                if (self.datasource != nil) {
                    cell.data = @[[self.datasource valueForKey:@"receiver_name"],
                                  [self.datasource valueForKey:@"receiver_mobile"],
                                  [self.datasource valueForKey:@"receiver_address"],
                                  ];
                }
                return cell;

            } else {
                NSInteger status = [[self.datasource valueForKey:@"status"] integerValue];
                if (status == STATUS_CLOSE) {
                    ZCOrderDetailAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderDetailAddressCell"
                                                                                     forIndexPath:indexPath];
                    if (self.datasource != nil) {
                        cell.data = @[[self.datasource valueForKey:@"receiver_name"],
                                      [self.datasource valueForKey:@"receiver_mobile"],
                                      [self.datasource valueForKey:@"receiver_address"],
                                      ];
                    }
                    return cell;
                } else {
                    if (row == 0) {
                        ZCOrderDetailLogisticsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderDetailLogisticsCell" forIndexPath:indexPath];
                        cell.dict = self.datasource;
                        return cell;
                    } else {
                        ZCOrderDetailAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderDetailAddressCell"
                                                                                         forIndexPath:indexPath];
                        if (self.datasource != nil) {
                            cell.data = @[[self.datasource valueForKey:@"receiver_name"],
                                          [self.datasource valueForKey:@"receiver_mobile"],
                                          [self.datasource valueForKey:@"receiver_address"],
                                          ];
                        }
                        return cell;
                    }
                }
                
            }
        }
            break;
        case 1:
        {
            ZCOrderCheckGoodsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderCheckGoodsInfoCell"
                                                                              forIndexPath:indexPath];
            NSArray *orderExtend = [self.datasource valueForKey:@"orderExtend"];
            NSDictionary *dict = orderExtend[row];
            cell.dict = dict;
            return cell;
        }
            break;
        case 2:
        {
            NSArray *arr = self.staticArr.firstObject;
            ZCOrderCheckLeftAndRightCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderCheckLeftAndRightCell"
                                                                                 forIndexPath:indexPath];
            cell.keystr = arr[row];
            cell.canCopy = NO;
            switch (row) {
                case 0: {
                    cell.valuestr = [self.datasource valueForKey:@"order_sn"];
                    cell.canCopy = YES;
                } break;
                case 1:{
                    cell.valuestr = [self.datasource valueForKey:@"goods_fee"];
                }
                    break;
                case 2: {
                    cell.valuestr = [self.datasource valueForKey:@"created_at"];
                } break;
                case 3: {
                    cell.valuestr = [self.datasource valueForKey:@"pay_time"];
                } break;
                case 4: {
                    cell.valuestr = [self.datasource valueForKey:@"send_time"];
                } break;
                    
                default:
                    break;
            }
            return cell;
        }
            break;
        case 3:
        {
            NSArray *arr = self.staticArr.lastObject;
            ZCOrderCheckLeftAndRightCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCOrderCheckLeftAndRightCell"
                                                                                 forIndexPath:indexPath];
            cell.keystr = arr[row];
            switch (row) {
                case 0: {
                    cell.valuestr = [[self.datasource valueForKey:@"nums"] stringValue];
                } break;
                case 1: {
                    NSString *str = [NSString stringWithFormat:@"￥%@",[self.datasource valueForKey:@"actual_fee"]];
                    cell.valuestr = str;
                } break;
                case 2:{
                        cell.valuestr = [self.datasource valueForKey:@"pay_type"];
                }
                    break;
                case 3: {
                    NSString *str = [NSString stringWithFormat:@"￥%@",[self.datasource valueForKey:@"freight_fee"]];
                    cell.valuestr = str;
                } break;
                case 4: {
                    NSString *str = [NSString stringWithFormat:@"￥%@",[self.datasource valueForKey:@"insurance_fee"]];
                    cell.valuestr = str;
                } break;
                case 5: {
                    NSString *str = [NSString stringWithFormat:@"￥%@",[self.datasource valueForKey:@"diff_fee"]];
                    cell.valuestr = str;
                } break;
                case 6: {
                    NSString *str = [NSString stringWithFormat:@"￥%@",[self.datasource valueForKey:@"coupon_fee"]];
                    cell.valuestr = str;
                } break;
                default:
                    break;
            }
            return cell;
        }
            break;
            
        default:
            return nil;
            break;
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        UINib *nib = [UINib nibWithNibName:@"ZCOrderPayHeadView" bundle:nil];
        ZCOrderPayHeadView *view = [nib instantiateWithOwner:self options:nil].firstObject;
        view.dict = self.datasource;
        return view;
    } else {
        if (section == 1) {
            UINib *nib = [UINib nibWithNibName:@"ZCOrderCheckSectionHeadView" bundle:nil];
            ZCOrderCheckSectionHeadView *view = [nib instantiateWithOwner:self options:nil].firstObject;
            view.title = @"商品信息";
            return view;
        }
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *v = [UIView new];
      v.backgroundColor = [generalToolBox getColorWithHexadecimalColorStr:@"0xf4f4f4"];
    return v;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    if (section == 0) {
        return UITableViewAutomaticDimension;
    }
    if (section == 1) {
        return UITableViewAutomaticDimension;
    }
    return 45.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 70;
    }
    if (section == 1) {
        return 45.0f;
    }
    return 0.001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 15.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (section == 1 && row == 0) {
//        WZGGoodsDetailVC *vc = [[WZGGoodsDetailVC alloc] init];
//        NSArray *orderExtend = [self.datasource valueForKey:@"orderExtend"];
//        NSDictionary *dict = orderExtend.firstObject;
//        vc.idstr = [dict valueForKey:@"goods_id"];
//        vc.bargainId = 0;
//        [self.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    NSInteger status = [[self.datasource valueForKey:@"status"] integerValue];
    if (status == STATUS_WAIT_GET || status == STATUS_END) {
        if (section == 0) {
            if (row == 0) {
                ZCLogisticsVC *vc = [[ZCLogisticsVC alloc] init];
                vc.logisticId = [self.datasource valueForKey:@"logistics_sn"];
                vc.expressId = [self.datasource valueForKey:@"express_code"];
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
    }
}

- (void)loadChatVC {
//    if (self.userModel.member.type > 1) {
//        WZGChatIMVC *vc = [[WZGChatIMVC alloc] init];
//        vc.fromType = WZGChatIMVCForm_Order;
//        vc.sn_code = self.ids;
//        vc.sn_type = @"1";
//        [self.navigationController pushViewController:vc animated:YES];
//    } else {
//        ZCLeaderShopVC *vc = [[ZCLeaderShopVC alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        vc.storeId = [NSString stringWithFormat:@"%ld",self.userModel.member.team_id];
//        [self.navigationController pushViewController:vc animated:YES];
//    }
}

// MARK: - NET

- (void)netFetchOrderDetail {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *dict = @{@"id":self.ids?self.ids:@"",@"referrer_uid":self.referrer_uid?self.referrer_uid:@""};
    [ZCOrderViewModel fetchOrderDetailWithOrderDict:dict complete:^(ZCErrorCode status, NSString *message, id data) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        if (status == kHXSNoError) {
            weakSelf.datasource = data;
            [weakSelf.tableView reloadData];
            [weakSelf updateBarView];
        } else if (status == kHXSInvalidTokenError) {
//            WZGLoginVC *vc = [[WZGLoginVC alloc] init];
//            [vc setGoodsVCCallBack:^(NSInteger type) {
//                [weakSelf netFetchOrderDetail];
//            }];
//            UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
//            nvc.modalPresentationStyle = UIModalPresentationFullScreen;
//            [weakSelf.navigationController presentViewController:nvc animated:YES completion:nil];
        } else {
            [weakSelf.view makeToast:message duration:2.0 position:CSToastPositionCenter];
        }
    }];
}

- (void)netConfirmReceipt {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [ZCOrderViewModel confirmreceiptWithOrderId:[self.datasource valueForKey:@"id"] complete:^(ZCErrorCode status, NSString *message, id data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        });
        if (status == kHXSNoError) {
            [weakSelf.view makeToast:@"签收成功" duration:2.0 position:CSToastPositionCenter];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf netFetchOrderDetail];
            });
            // 去评价
            [self showAlert:@"" content:@"亲，您当前订单已完成，\n请进行评价～" actionStr1:@"取消" style:UIAlertActionStyleDefault actionAc1:^(UIAlertAction * _Nonnull action) {
                
            } actionStr2:@"去评价" style:UIAlertActionStyleDestructive actionAc:^(UIAlertAction * _Nonnull action) {
                // 评价
//                WZGAddCommentVC *addCommentVC = [[WZGAddCommentVC alloc] init];
//                WZGCommentOrderModel *orderItem = [[WZGCommentOrderModel alloc] init];
//                orderItem.order_id = [self.datasource valueForKey:@"id"];
//                addCommentVC.isSaleAfter = false;
//                addCommentVC.orderItem = orderItem;
//                [weakSelf.navigationController pushViewController:addCommentVC animated:true];
            }];
            
        } else if (status == kHXSInvalidTokenError) {
//            WZGLoginVC *vc = [[WZGLoginVC alloc] init];
//            [vc setGoodsVCCallBack:^(NSInteger type) {
//                [weakSelf netFetchOrderDetail];
//            }];
//            UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
//            nvc.modalPresentationStyle = UIModalPresentationFullScreen;
//            [weakSelf.navigationController presentViewController:nvc animated:YES completion:nil];
        } else {
            [weakSelf.view makeToast:message duration:2.0 position:CSToastPositionCenter];
        }
    }];
}

- (void)netDelOrder {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [ZCOrderViewModel delOrderWithId:[self.datasource valueForKey:@"id"] complete:^(ZCErrorCode status, NSString *message, id data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        });
        if (status == kHXSNoError) {
            [weakSelf.view makeToast:@"删除订单成功" duration:2.0 position:CSToastPositionCenter];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
        } else if (status == kHXSInvalidTokenError) {
//            WZGLoginVC *vc = [[WZGLoginVC alloc] init];
//            [vc setGoodsVCCallBack:^(NSInteger type) {
//                [weakSelf netFetchOrderDetail];
//            }];
//            UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
//            nvc.modalPresentationStyle = UIModalPresentationFullScreen;
//            [weakSelf.navigationController presentViewController:nvc animated:YES completion:nil];
        } else {
            [weakSelf.view makeToast:message duration:2.0 position:CSToastPositionCenter];
        }
    }];
}

- (void)netFetchOrderCanselResion {
    __weak typeof(self) weakSelf = self;
    [ZCOrderViewModel fetchOrderCanselResionWithComplete:^(ZCErrorCode status, NSString *message, id data) {
        ZCOrderCanselResionVC *vc = [[ZCOrderCanselResionVC alloc] init];
        weakSelf.definesPresentationContext = YES;
        [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
        vc.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
        vc.items = data;
        [vc setDoneCallback:^(NSDictionary *dict) {
            [weakSelf netCanselOrderWithId:[weakSelf.datasource valueForKey:@"id"] causeId:[dict valueForKey:@"id"]];
        }];
        [weakSelf.view.window.rootViewController presentViewController:vc animated:YES completion:^{
            [UIView animateWithDuration:0.3 animations:^{
                vc.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
            }];
        }];
    }];
}

- (void)netCanselOrderWithId:(NSString *)idstr causeId:(NSString *)causeId {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [ZCOrderViewModel canselOrderWithId:idstr causeId:causeId complete:^(ZCErrorCode status, NSString *message, id data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        });
        if (status == kHXSInvalidTokenError) {
//            WZGLoginVC *vc = [[WZGLoginVC alloc] init];
//            [vc setGoodsVCCallBack:^(NSInteger type) {
//                [weakSelf netFetchOrderDetail];
//            }];
//            UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
//            nvc.modalPresentationStyle = UIModalPresentationFullScreen;
//            [weakSelf.parentViewController.navigationController presentViewController:nvc animated:YES completion:nil];
        } else if (status == kHXSNoError) {
            [weakSelf.view makeToast:@"操作成功" duration:2.0 position:CSToastPositionCenter];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
        } else {
            [weakSelf.view makeToast:message duration:2.0 position:CSToastPositionCenter];
        }
    }];
}

// MARK: - GET

- (NSArray *)staticArr {
    if (_staticArr == nil) {
        _staticArr = @[@[@"订单编号：",
                         @"商品合计：",
                         @"提交时间：",
                         @"付款时间",
                         @"发货时间"],
                       
                       @[@"商品总件数：",
                         @"订单金额：",
                         @"支付方式：",
                         @"运费：",
                         @"退换省心服务：",
                         @"收益：",
                         @"优惠金额：",],];
    }
    return _staticArr;
}

@end
